package GUI;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.io.IOException;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JOptionPane;

import Messages.MessageDeleteBusinessMenu;
import Messages.MessageGetAllRecipes;
import Messages.MessageGetAllRecipesReply;
import Messages.MessageShowAllStandardsMenus;
import Messages.MessageShowAllStandardsMenusReply;
import Messages.MessageShowBusinessMenus;
import Messages.MessageShowBusinessMenusReply;

public class PanelFunctionMenuAllStandartsMenu  extends PanelFunctionsEmpty{
	private static final long serialVersionUID = 1L;
	private JButton button_Menu;
	private JButton button_editMenu;
	private JButton button_deleteMenu;
	private JButton button_ListStandMenu;
	private JButton button_ListRecipes;
	private JButton button_HomeScreen;
	private JButton button_ListBussMenu;
	private MainMenu mainMenu;
	private String GeneralMenu;
	private Vector<String> menus;
	
	
public PanelFunctionMenuAllStandartsMenu(MainMenu mm,Vector <String> menus)
{
	super();	
	this.mainMenu=mm;
	this.menus=menus;
	this.add(get_button_editMenu());
	this.add(get_button_BuildNewMenu());
	this.add(get_button_deleteMenu());
	this.add(get_button_listAllBusinessMenu()); 
	this.add(get_button_listAllRecipes());
	this.add(get_button_HomeScreen());
	GeneralMenu="1";
}
	
	
	
	
private JButton get_button_BuildNewMenu() 
	{
		if (button_Menu == null) 
		{			
			button_Menu=new JButton("לבנות תפריט רגיל");  			 
			button_Menu.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_Menu.setPreferredSize(new Dimension(220, 30));
			
			button_Menu.addActionListener(new java.awt.event.ActionListener() 
			   {
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
									
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
					mainMenu.getContentPane().add(new PFAddNewStandartMenu(mainMenu), BorderLayout.CENTER);	
					mainMenu.getContentPane().add(new PanelFunctionEmptyWithoutKeyboard(mainMenu), BorderLayout.EAST);
					mainMenu.getContentPane().validate();						
				}
			});
		}
		return button_Menu;
	}
	
private JButton get_button_editMenu() 
{
	
	if (button_editMenu == null) 
	{			
		button_editMenu=new JButton("לעדכן תפריט רגיל ");  			 
		button_editMenu.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_editMenu.setPreferredSize(new Dimension(220, 30));
		
		button_editMenu.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				if(menus.isEmpty()) {
					JOptionPane.showMessageDialog(null,"יש לבחור תפריט");
		    		 return;
				
				}
				else{
					
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					mainMenu.getContentPane().add(new PfUpdateStandardMenu(mainMenu,menus), BorderLayout.CENTER);					
					mainMenu.getContentPane().validate();		
						}
			}
		});
	}
	return button_editMenu;
}

private JButton get_button_deleteMenu() 
{
	if (button_deleteMenu == null) 
	{			
		button_deleteMenu=new JButton("למחוק תפריט רגיל");  			 
		button_deleteMenu.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_deleteMenu.setPreferredSize(new Dimension(220, 30));
		
		button_deleteMenu.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				if(menus.isEmpty()) {
					JOptionPane.showMessageDialog(null,"יש לבחור מתכון");
		    		 return;
				
				}
				else
				{
					int n = JOptionPane.showConfirmDialog(
						    null,
						    "    אתה בטוח?",
						    "    בקשת אישור  ",
						    JOptionPane.YES_NO_OPTION);
					 
					 if(n!=1){
                     MessageDeleteBusinessMenu msgDelMenu=new MessageDeleteBusinessMenu (menus.get(0));
                     
						try {
							mainMenu.ms.client.sendToServer(msgDelMenu);
							mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
							MessageShowBusinessMenus msgShowMenu=new MessageShowBusinessMenus( );
							mainMenu.ms.client.sendToServer(msgShowMenu);
							MessageShowBusinessMenusReply resultMenu=(MessageShowBusinessMenusReply)mainMenu.ms.client.GetMessage();
							mainMenu.getContentPane().add(new PfSearch_business_menu(mainMenu,resultMenu.getResultMenu()), BorderLayout.CENTER);	
							mainMenu.getContentPane().validate();
						}
					
					catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
											
					}
				 }		
			}
				 }
		});
	}
	return button_deleteMenu;
}

private JButton get_button_listAllBusinessMenu() 
{   final Vector<String> arr = new Vector<String>();
	if (button_ListBussMenu == null) 
	{			
		button_ListBussMenu=new JButton("רשימת תפריטים עסקיים"); 
		if(this.mainMenu.getUser().getPermission()!=3)
			button_ListBussMenu.setEnabled(false);
		button_ListBussMenu.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_ListBussMenu.setPreferredSize(new Dimension(220, 30));
		
		button_ListBussMenu.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				MessageShowBusinessMenus msgShowMenu=new MessageShowBusinessMenus( );
				
				try {
					mainMenu.ms.client.sendToServer(msgShowMenu);
					MessageShowBusinessMenusReply resultMenu=(MessageShowBusinessMenusReply)mainMenu.ms.client.GetMessage();
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					mainMenu.getContentPane().add(new PfSearch_business_menu(mainMenu,resultMenu.getResultMenu()), BorderLayout.CENTER);	
					mainMenu.getContentPane().add(new PanelFunctionMenuListAllBusMenu(mainMenu,arr), BorderLayout.EAST);
					mainMenu.getContentPane().validate();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				System.out.println("tables actionPerformed()"); 							
			}
		});
	}
	return button_ListBussMenu;
}
private JButton get_button_listAllRecipes() 
{
	final Vector<String> arr1 = new Vector<String>();
	if (button_ListRecipes == null) 
	{			
		button_ListRecipes=new JButton("רשימת מתכונים"); 
		if(this.mainMenu.getUser().getPermission()!=3)
			button_ListRecipes.setEnabled(false);
		button_ListRecipes.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_ListRecipes.setPreferredSize(new Dimension(220, 30));
		
		button_ListRecipes.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				
				MessageGetAllRecipes msgShowMenu=new MessageGetAllRecipes( );
				
				try {
					mainMenu.ms.client.sendToServer(msgShowMenu);
					MessageGetAllRecipesReply resultMenu=(MessageGetAllRecipesReply)mainMenu.ms.client.GetMessage();
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
				mainMenu.getContentPane().add(new PfShow_all_recipes(mainMenu,resultMenu.getRecipes()), BorderLayout.CENTER);	
				mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
				mainMenu.getContentPane().add(new PanelFunctionListOfAllRecipes(mainMenu, arr1), BorderLayout.EAST);
				mainMenu.getContentPane().validate();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
	}
	return button_ListRecipes;
}

//-----Return to first screen in this module 
private JButton get_button_HomeScreen() 
{
	if (button_HomeScreen == null) 
	{			
		button_HomeScreen=new JButton("תפריט ראשי"); 
		if(this.mainMenu.getUser().getPermission()!=3)
			button_HomeScreen.setEnabled(false);
		button_HomeScreen.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_HomeScreen.setPreferredSize(new Dimension(220, 30));
		
		button_HomeScreen.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
                MessageShowBusinessMenus msgShowMenu=new MessageShowBusinessMenus( );
				
				try {
					mainMenu.ms.client.sendToServer(msgShowMenu);
					MessageShowBusinessMenusReply resultMenu=(MessageShowBusinessMenusReply)mainMenu.ms.client.GetMessage();
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					mainMenu.getContentPane().add(new PfSearch_business_menu(mainMenu,resultMenu.getResultMenu()), BorderLayout.CENTER);	
					mainMenu.getContentPane().add(new PanelFunctionsManagementMenu(mainMenu), BorderLayout.EAST);
					mainMenu.getContentPane().validate();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				System.out.println("tables actionPerformed()"); 							
			}
		});
	}
	return button_HomeScreen;
	


}

}



